<?php
/**
 * 获取分类
 */
global $_W, $_GPC;

$act = $_GPC['act'] ? $_GPC['act'] : 'list';

if ($act == 'list') {
    $condition = array('status' => 1);
    $fields = array('id', 'name', 'image');
    $keyField = '';
    $orderBy = array('sort desc');
    $limit = array(0, 10);
    $list = M('category')->getAll($condition, $fields, $keyField, $orderBy, $limit);
    if (!empty($list)) {
        foreach ($list as $key => $value) {
            $list[$key]['image'] = tomedia($value['image']);
        }
    }
    $this->result(0, '获取到分类', $list);
}

if ($act == 'info') {
    $categoryId = intval($_GPC['categoryId']);
    $category = M('category')->getInfo($categoryId);
    $this->result(0, '获取到分类', $category);
}